package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.customer.domain.vo.MallProductImgVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.MallProductImg;
import com.ktgj.customer.service.IMallProductImgService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 商品图片Controller
 * 
 * @author ruoyi
 * @date 2022-05-30
 */
@RestController
@RequestMapping("/MallProductImg")
public class MallProductImgController extends BaseController
{
    @Autowired
    private IMallProductImgService mallProductImgService;

    /**
     * 查询商品图片列表
     */
    @PreAuthorize(hasPermi = "customer:img:list")
    @GetMapping("/list")
    public TableDataInfo list(MallProductImg mallProductImg)
    {
        startPage();
        List<MallProductImg> list = mallProductImgService.selectMallProductImgList(mallProductImg);
        return getDataTable(list);
    }

    /**
     * 导出商品图片列表
     */
    @PreAuthorize(hasPermi = "customer:img:export")
    @Log(title = "商品图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallProductImg mallProductImg) throws IOException
    {
        List<MallProductImg> list = mallProductImgService.selectMallProductImgList(mallProductImg);
        ExcelUtil<MallProductImg> util = new ExcelUtil<MallProductImg>(MallProductImg.class);
        util.exportExcel(response, list, "商品图片数据");
    }

    /**
     * 获取商品图片详细信息
     */
    @PreAuthorize(hasPermi = "customer:img:query")
    @GetMapping(value = "/{productImgId}")
    public AjaxResult getInfo(@PathVariable("productImgId") Long productImgId)
    {
        return AjaxResult.success(mallProductImgService.selectMallProductImgById(productImgId));
    }

    /**
     * 新增商品图片
     */
    @PreAuthorize(hasPermi = "customer:img:add")
    @Log(title = "商品图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallProductImg mallProductImg)
    {
        return toAjax(mallProductImgService.insertMallProductImg(mallProductImg));
    }

    /**
     * 修改商品图片
     */
    @PreAuthorize(hasPermi = "customer:img:edit")
    @Log(title = "商品图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallProductImg mallProductImg)
    {
        return toAjax(mallProductImgService.updateMallProductImg(mallProductImg));
    }

    /**
     * 删除商品图片
     */
    @PreAuthorize(hasPermi = "customer:img:remove")
    @Log(title = "商品图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productImgIds}")
    public AjaxResult remove(@PathVariable Long[] productImgIds)
    {
        return toAjax(mallProductImgService.deleteMallProductImgByIds(productImgIds));
    }

    /**
     * 商城图片管理
     * @param mallProductImg
     * @return
     */
    @PostMapping("/insertProductImg")
    public AjaxResult insertProductImg(@RequestBody MallProductImgVO mallProductImg) {
        return toAjax(mallProductImgService.insertProductImg(mallProductImg));
    }
}
